package com.groupseven.backend.services.impl;

import com.groupseven.backend.domain.PrizeProduct.PrizeProduct;
import com.groupseven.backend.mapper.PaperMapper;
import com.groupseven.backend.mapper.PatentMapper;
import com.groupseven.backend.mapper.PrizeProductMapper;
import com.groupseven.backend.services.PrizeProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class PrizeProductServiceImpl implements PrizeProductService {
    @Autowired
    private PrizeProductMapper prizeProductMapper;
    @Autowired
    private PatentMapper patentMapper;
    @Autowired
    private PaperMapper paperMapper;

    public List<PrizeProduct> getallPrizeProduct(){
        return prizeProductMapper.getallPrizeProduct();
    }

    public PrizeProduct getPrizeProductByPrizeProductNumber(String PrizeProductNumber){
        return prizeProductMapper.getPrizeProductByPrizeProductNumber(PrizeProductNumber);
    }

    public int addPrizeProduct(PrizeProduct prizeProduct){
        if(prizeProductMapper.getPrizeProductByPrizeProductNumber(prizeProduct.PrizeProductNumber)!=null){
            return -1;
        }
//        else if(prizeProduct.PatentNumber==null){
//            if(paperMapper.selectByPaperNumber(prizeProduct.PaperNumber)==null){
//                return -2;
//            }
//            else {
//                prizeProductMapper.addPrizeProduct(prizeProduct);
//                return 2;
//            }
//        }
//        else if(prizeProduct.PaperNumber==null){
//            if(patentMapper.getPatentByPatentNumber(prizeProduct.PatentNumber)==null){
//                return -3;
//            }
//            else {
//                prizeProductMapper.addPrizeProduct(prizeProduct);
//                return 3;
//            }
//        }
//        else {
//            if(patentMapper.getPatentByPatentNumber(prizeProduct.PatentNumber)==null&&paperMapper.selectByPaperNumber(prizeProduct.PaperNumber)==null){
//                return -5;
//            }
//            else if(patentMapper.getPatentByPatentNumber(prizeProduct.PatentNumber)!=null&&paperMapper.selectByPaperNumber(prizeProduct.PaperNumber)==null){
//                return -6;
//            }
//            else if(patentMapper.getPatentByPatentNumber(prizeProduct.PatentNumber)==null&&paperMapper.selectByPaperNumber(prizeProduct.PaperNumber)!=null){
//                return -7;
//            }
//            else {
//                prizeProductMapper.addPrizeProduct(prizeProduct);
//                return 5;
//            }
//        }
//        else if(prizeProductMapper.getProgramNumber(prizeProduct.ProgramNumber)==null){
//            return -2;
//        }
        else {
            prizeProductMapper.addPrizeProduct(prizeProduct);
            return 5;
        }
    }

    public int updatePrizeProduct(PrizeProduct prizeProduct){
//        if(prizeProductMapper.getPrizeProductByPrizeProductNumber(prizeProduct.PrizeProductNumber)==null){
//            return -1;
//        }
//        else if(prizeProduct.PatentNumber==null){
//            if(paperMapper.selectByPaperNumber(prizeProduct.PaperNumber)==null){
//                return -2;
//            }
//            else {
//                prizeProductMapper.addPrizeProduct(prizeProduct);
//                return 2;
//            }
//        }
//        else if(prizeProduct.PaperNumber==null){
//            if(patentMapper.getPatentByPatentNumber(prizeProduct.PatentNumber)==null){
//                return -3;
//            }
//            else {
//                prizeProductMapper.addPrizeProduct(prizeProduct);
//                return 3;
//            }
//        }
//      else {
//            if(patentMapper.getPatentByPatentNumber(prizeProduct.PatentNumber)==null&&paperMapper.selectByPaperNumber(prizeProduct.PaperNumber)==null){
//                return -5;
//            }
//            else if(patentMapper.getPatentByPatentNumber(prizeProduct.PatentNumber)!=null&&paperMapper.selectByPaperNumber(prizeProduct.PaperNumber)==null){
//                return -6;
//            }
//            else if(patentMapper.getPatentByPatentNumber(prizeProduct.PatentNumber)==null&&paperMapper.selectByPaperNumber(prizeProduct.PaperNumber)!=null){
//                return -7;
//            }
//            else {
//                prizeProductMapper.addPrizeProduct(prizeProduct);
//                return 5;
//            }
//        else if (prizeProductMapper.getProgramNumber(prizeProduct.ProgramNumber)==null){
//            return -2;
//        }
//        else {
            prizeProductMapper.updatePrizeProduct(prizeProduct);
            return 1;
//        }
    }

    public int deleteallPrizeProduct(){
        return prizeProductMapper.deleteallPrizeProduct();
    }

    public int deleteByPrizeProductNumber(String PrizeProductNumber){
        if(prizeProductMapper.getPrizeProductByPrizeProductNumber(PrizeProductNumber)==null){
            return 0;
        }
        else {
            prizeProductMapper.deleteByPrizeProductNumber(PrizeProductNumber);
            return 1;
        }
    }

    /////////////////////////////////////////////////////////////////////////////
    public int mutildelPrizeProducts(List<String> PrizeProductNumbers){
        return prizeProductMapper.mutildelPrizeProducts(PrizeProductNumbers);
    }
    public List<PrizeProduct> getlikePrizeProductByPrizeProductNumber(String PrizeProductNumber){
        return prizeProductMapper.getlikePrizeProductByPrizeProductNumber(PrizeProductNumber);
    }
    public List<PrizeProduct> getlikePrizeProductByPrizeProductName(String ProductName){
        return prizeProductMapper.getlikePrizeProductByPrizeProductName(ProductName);
    }

    public List<PrizeProduct> getlikePrizeProductByusername(String username){
        return prizeProductMapper.getlikePrizeProductByusername(username);
    }

    public List<PrizeProduct> getlikePrizeProductByPrizeAllauthors(String PrizeAllauthors){
        return prizeProductMapper.getlikePrizeProductByPrizeAllauthors(PrizeAllauthors);
    }

///////////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////
    public List<PrizeProduct> searchqueryPrizeProduct(String query){
        return prizeProductMapper.searchqueryPrizeProduct(query);
    }
    //////////////////////////////////////////////

    //////////////////////////////////////////
    public List<PrizeProduct> searchuserqueryPrizeProduct (String query, String username){
        return prizeProductMapper.searchuserqueryPrizeProduct(query,username);
    }
    //////////////////////////////////////
}
